package com.study.zzedu.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.study.zzedu.R;
import com.study.zzedu.entity.CourseDetailItem;
import com.study.zzedu.entity.TeachProgramItem;

import org.json.JSONArray;

import java.util.List;

public class TeachProgramAdapter extends RecyclerView.Adapter<TeachProgramAdapter.MViewHolder> {

    private List<TeachProgramItem> m;
    public TeachProgramAdapter(List<TeachProgramItem> mList) {
        this.m = mList;
    }

    public MViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_teach_program,parent,false);
        MViewHolder holder = new MViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull MViewHolder holder, int position) {
        if(m.size()<1)
            return;
        TeachProgramItem s = m.get(position);

        if(s.getType() == TeachProgramItem.Type.SENCOD){
            holder.title.setText("  "+s.getTitle());
        }else  if(s.getType() == TeachProgramItem.Type.THIED){
            holder.title.setText("    "+s.getTitle());
        }else {
            if(0 == position)
                holder.title.setText(s.getTitle());
            else {
                holder.title.setText("\n"+s.getTitle());
            }
        }
    }

    @Override
    public int getItemCount() {
        return m.size();
    }

    public class MViewHolder extends RecyclerView.ViewHolder{
        TextView title;
        public MViewHolder(View mView) {
            super(mView);
            title = (TextView) mView.findViewById(R.id.tv_title);
        }
    }
}
